package com.pn.controller;

import com.pn.entity.User;
import com.pn.util.ResponseMsg;
import com.pn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/lg")
    public ResponseMsg userLogin(@RequestBody User u){
        System.out.println("正在对请求做处理..." + u);
        ResponseMsg responseMsg = userService.checkLoginInfo(u);
        if(responseMsg.getRespStatusCode() == 200){
            Integer updatedTime = userService.updateLast_inByPhone(u.getPhone());
            if(updatedTime == 1) {
                System.out.println("该用户登陆时间更新成功！");
            } else System.out.println("该用户登录时间更新失败...");
        }
        return responseMsg;
    }

    @PostMapping("/rg")
    public ResponseMsg userRegister(@RequestBody User u){
        System.out.println("正在对注册请求做处理" + u);
        ResponseMsg responseMsg = userService.insertNewUser(u);
        return responseMsg;
    }
}
